package HLLib.ui;

import HLCode.HLClass;
import HLCode.HLClassManager;
import HLCode.HLClassManager_H;
import HLCode.HLObject;
import HLLib.base.HLGraphics;
import HLLib.base.HLRectangle;
import HLLib.io.HLFile;

public class HLUIControlFrame extends HLUIControl {
    public HLClass GetClass(HLClassManager classManager) {
        return classManager.GetLibClass(HLClassManager_H.CLASS_GROUP_TYPE_LIB_UI, HLClassManager_H.LIB_CLASS_UI_UIControlFrame);
    }

    public int GetInt(int index) {
        switch (index) {
        case 1: {
            return frameIndex;
        }
        }
        return super.GetInt(index);
    }

    public void SetInt(int index, int value) {
        switch (index) {
        case 1: {
            frameIndex = value;
            return;
        }
        }
        super.SetInt(index, value);
    }

    public boolean GetBoolean(int index) {
        return super.GetBoolean(index);
    }

    public void SetBoolean(int index, boolean value) {
        super.SetBoolean(index, value);
    }

    public HLObject GetObject(int index) {
        return super.GetObject(index);
    }

    public void SetObject(int index, HLObject value) {
        super.SetObject(index, value);
    }

    public int frameIndex;

    public HLUIControlFrame() {
    }

    HLUIControlFrame(HLUIFrame frame) {
        super(frame);
    }

    public HLUIFrame GetFrame() {
        return (HLUIFrame) ownerFrame.owner.frames.items[frameIndex];
    }

    void Load(HLFile file) {
        super.Load(file);
        frameIndex = file.ReadUInt16();
    }

    void Render(HLGraphics g, int rectX, int rectY, int rectWidth, int rectHeight, int color) {
        HLRectangle area = GetArea(rectX, rectY, rectWidth, rectHeight);
        GetFrame().RenderEX(g, area.x, area.y, area.width, area.height, color);
    }

    HLUIControl FindControl(int id) {
        return GetFrame().FindControl(id);
    }

    HLRectangle FindControlArea(int id, int rectX, int rectY, int rectWidth, int rectHeight) {
        HLRectangle area = GetArea(rectX, rectY, rectWidth, rectHeight);
        return GetFrame().FindControlArea(id, area.x, area.y, area.width, area.height);
    }
    
    void CopyFrom(HLUIControl uiControl) {
        super.CopyFrom(uiControl);
        
        HLUIControlFrame uiControlByType = (HLUIControlFrame) uiControl;

        frameIndex = uiControlByType.frameIndex;
    }

    HLUIControl Clone(HLUIFrame ownerFrame) {
        HLUIControlFrame uiControl = new HLUIControlFrame();
        uiControl.ownerFrame = ownerFrame;
        uiControl.CopyFrom(this);
        return uiControl;
    }
}
